home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bcdtext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  6.1 KB  |  202 lines

  1. /* 
  2.  *
  3.  * $Id: k3bcdtext.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef _K3B_CDTEXT_H_
  18. #define _K3B_CDTEXT_H_
  19.  
  20. #include <qstring.h>
  21. #include <qvaluevector.h>
  22. #include "k3bdevice_export.h"
  23.  
  24. namespace K3bDevice
  25. {
  26.   struct cdtext_pack;
  27.  
  28.   class TrackCdText
  29.     {
  30.       friend class Device;
  31.       
  32.     public:
  33.       TrackCdText() {
  34.       }
  35.  
  36.       void clear() {
  37.     m_title.truncate(0);
  38.     m_performer.truncate(0);
  39.     m_songwriter.truncate(0);
  40.     m_composer.truncate(0);
  41.     m_arranger.truncate(0);
  42.     m_message.truncate(0);
  43.     m_isrc.truncate(0);
  44.       }
  45.  
  46.       const QString& title() const { return m_title; }
  47.       const QString& performer() const { return m_performer; }
  48.       const QString& songwriter() const { return m_songwriter; }
  49.       const QString& composer() const { return m_composer; }
  50.       const QString& arranger() const { return m_arranger; }
  51.       const QString& message() const { return m_message; }
  52.       const QString& isrc() const { return m_isrc; }
  53.  
  54.       // TODO: use the real CD-TEXT charset (a modified ISO8859-1)
  55.       void setTitle( const QString& s ) { m_title = s; fixup(m_title); }
  56.       void setPerformer( const QString& s ) { m_performer = s; fixup(m_performer); }
  57.       void setSongwriter( const QString& s ) { m_songwriter = s; fixup(m_songwriter); }
  58.       void setComposer( const QString& s ) { m_composer = s; fixup(m_composer); }
  59.       void setArranger( const QString& s ) { m_arranger = s; fixup(m_arranger); }
  60.       void setMessage( const QString& s ) { m_message = s; fixup(m_message); }
  61.       void setIsrc( const QString& s ) { m_isrc = s; fixup(m_isrc); }
  62.  
  63.       bool isEmpty() const {
  64.     if( !m_title.isEmpty() )
  65.       return false;
  66.     if( !m_performer.isEmpty() )
  67.       return false;
  68.     if( !m_songwriter.isEmpty() )
  69.       return false;
  70.     if( !m_composer.isEmpty() )
  71.       return false;
  72.     if( !m_arranger.isEmpty() )
  73.       return false;
  74.     if( !m_message.isEmpty() )
  75.       return false;
  76.     if( !m_isrc.isEmpty() )
  77.       return false;
  78.  
  79.     return true;
  80.       }
  81.  
  82.       bool operator==( const TrackCdText& ) const;
  83.       bool operator!=( const TrackCdText& ) const;
  84.  
  85.     private:
  86.       // TODO: remove this (see above)
  87.       void fixup( QString& s ) { s.replace( '/', "_" ); s.replace( '\"', "_" ); }
  88.  
  89.       QString m_title;
  90.       QString m_performer;
  91.       QString m_songwriter;
  92.       QString m_composer;
  93.       QString m_arranger;
  94.       QString m_message;
  95.       QString m_isrc;
  96.  
  97.       friend class CdText;
  98.     };
  99.  
  100.   class LIBK3BDEVICE_EXPORT CdText : public QValueVector<TrackCdText>
  101.     {
  102.       friend class Device;
  103.  
  104.     public:
  105.       CdText();
  106.       CdText( const unsigned char* data, int len );
  107.       CdText( const QByteArray& );
  108.       CdText( int size );
  109.       CdText( const CdText& );
  110.  
  111.       void setRawPackData( const unsigned char*, int );
  112.       void setRawPackData( const QByteArray& );
  113.  
  114.       QByteArray rawPackData() const;
  115.  
  116.       bool empty() const {
  117.     if( !m_title.isEmpty() )
  118.       return false;
  119.     if( !m_performer.isEmpty() )
  120.       return false;
  121.     if( !m_songwriter.isEmpty() )
  122.       return false;
  123.     if( !m_composer.isEmpty() )
  124.       return false;
  125.     if( !m_arranger.isEmpty() )
  126.       return false;
  127.     if( !m_message.isEmpty() )
  128.       return false;
  129.     if( !m_discId.isEmpty() )
  130.       return false;
  131.     if( !m_upcEan.isEmpty() )
  132.       return false;
  133.     
  134.     for( unsigned int i = 0; i < count(); ++i )
  135.       if( !at(i).isEmpty() )
  136.         return false;
  137.  
  138.     return true;
  139.       }
  140.  
  141.       bool isEmpty() const {
  142.     return empty();
  143.       }
  144.  
  145.       void clear();
  146.  
  147.       const QString& title() const { return m_title; }
  148.       const QString& performer() const { return m_performer; }
  149.       const QString& songwriter() const { return m_songwriter; }
  150.       const QString& composer() const { return m_composer; }
  151.       const QString& arranger() const { return m_arranger; }
  152.       const QString& message() const { return m_message; }
  153.       const QString& discId() const { return m_discId; }
  154.       const QString& upcEan() const { return m_upcEan; }
  155.  
  156.       // TODO: use the real CD-TEXT charset (a modified ISO8859-1)
  157.       void setTitle( const QString& s ) { m_title = s; fixup(m_title); }
  158.       void setPerformer( const QString& s ) { m_performer = s; fixup(m_performer); }
  159.       void setSongwriter( const QString& s ) { m_songwriter = s; fixup(m_songwriter); }
  160.       void setComposer( const QString& s ) { m_composer = s; fixup(m_composer); }
  161.       void setArranger( const QString& s ) { m_arranger = s; fixup(m_arranger); }
  162.       void setMessage( const QString& s ) { m_message = s; fixup(m_message); }
  163.       void setDiscId( const QString& s ) { m_discId = s; fixup(m_discId); }
  164.       void setUpcEan( const QString& s ) { m_upcEan = s; fixup(m_upcEan); }
  165.  
  166.       void debug() const;
  167.  
  168.       /**
  169.        * Returns false if found a crc error in the raw cdtext block or it has a
  170.        * wrong length.
  171.        */
  172.       static bool checkCrc( const unsigned char*, int );
  173.       static bool checkCrc( const QByteArray& );
  174.  
  175.       bool operator==( const CdText& ) const;
  176.       bool operator!=( const CdText& ) const;
  177.     
  178.     private:
  179.       // TODO: remove this (see above)
  180.       void fixup( QString& s ) { s.replace( '/', "_" ); s.replace( '\"', "_" ); }
  181.  
  182.       const QString& textForPackType( int packType, unsigned int track ) const;
  183.       unsigned int textLengthForPackType( int packType ) const;
  184.       QByteArray createPackData( int packType, unsigned int& ) const;
  185.       void savePack( cdtext_pack* pack, QByteArray& data, unsigned int& dataFill ) const;
  186.       void appendByteArray( QByteArray& a, const QByteArray& b ) const;
  187.  
  188.       QString m_title;
  189.       QString m_performer;
  190.       QString m_songwriter;
  191.       QString m_composer;
  192.       QString m_arranger;
  193.       QString m_message;
  194.       QString m_discId;
  195.       QString m_upcEan;
  196.     };
  197.  
  198.   QCString encodeCdText( const QString& s, bool* illegalChars = 0 );
  199. }
  200.  
  201. #endif
  202.